#!/usr/bin/env python3
#-*- coding:utf-8 -*-
import os
import requests

base_path="/yll"

def storage_local(keyword,images):
    #根据搜索关键字创建子文件夹，用于放置改关键字搜索得到的图片
    dict_folder_path = "%s/%s"%(base_path,keyword)
    if not os.path.exists(dict_folder_path):
        os.makedirs(dict_folder_path)


    for image in images:
        #有none的判断一下
        if image:
            # build 保存图片的全路径名
            dict_image_path="%s/%s_%s.%s"%(dict_folder_path,keyword,images.index(image),image.split(".")[-1])
            # print(dict_folder_path)

            #图片二进制内容写入文件
            result = requests.get(image).content
            with open(dict_image_path,"wb") as f:
                f.write(result)


if __name__ == '__main__':
    # storage_local("yll",[])
    pass